import { createRouter, createWebHashHistory, createWebHistory } from "vue-router"
import Layout from '@/layout/index.vue'

export const asyncRoutes = [
  {
    id: 1,
    text: '学生管理',
    icon: 'Watch',
    path: '/student',
    alias: '/',     // 别名
    component: Layout,
    redirect: '/student/a',
    children: [
      { id: 11, text: '学生列表', path: '/student/a', component: () => import('@/pages/student/PageA.vue') },
      { id: 12, text: '添加学生', path: '/student/b', component: () => import('@/pages/student/PageB.vue') }
    ]
  },
  {
    id: 2,
    text: '老师管理',
    icon: 'Mouse',
    path: '/teacher',
    component: Layout,
    redirect: '/teacher/a',
    children: [
      { id: 21, text: '老师列表', path: '/teacher/a', component: () => import('@/pages/teacher/PageA.vue') },
      { id: 22, text: '添加老师', path: '/teacher/b', component: () => import('@/pages/teacher/PageB.vue') },
    ]
  },
]

const router = createRouter({
  history: createWebHashHistory(), // 使用hash路由  
  routes: [
    ...asyncRoutes,
    {
      path: "/*", redirect: "/"
    }
  ]
});

router.beforeEach((to, from, next) => {
  next();
})

export default router;